package com.example.demo.service.Impl;


import com.example.demo.bean.BaseLog;
import com.example.demo.bean.BaseLogExample;
import com.example.demo.dao.BaseLogMapper;
import com.example.demo.service.IBaseLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class BaseLogServiceImpl implements IBaseLogService {

    @Autowired
    private BaseLogMapper baseLogMapper;

    @Override
    public List<BaseLog> query(String realname) {
        BaseLogExample example = new BaseLogExample();
        if (!StringUtils.isEmpty(realname)) {
            example.createCriteria().andRealnameLike("%"+realname+"%");

        }
        List<BaseLog> list = baseLogMapper.selectByExample(example);
        return list;

    }

    @Override
    public void saveOrUpdate(BaseLog baseLog) {
     if(baseLog.getId()==null){
         baseLogMapper.insert(baseLog);
     }
     else{
         baseLogMapper.updateByPrimaryKey(baseLog);
     }

    }

    @Override
    public void deleteById(long id) {
       baseLogMapper.deleteByPrimaryKey(id);
    }
}
